<?php
/**
 * Created by PhpStorm.
 * User: prg
 * Date: 2017/3/9
 * Time: 11:12
 */

//管理员删除新闻接口
require_once 'db.php';
require_once 'response.php';

header('content-type:text/html;charset:utf-8');
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:GET,POST');
header('Access-Control-Allow-Headers:x-requested-with,content-type');

$id = isset($_POST['newsId']) ? $_POST['newsId'] : '';

if(!is_numeric($id)) {
    return Response::show(401,'数据不合法');
}

try{
    $connect = Db::getInstance()->connect();
} catch (Exception $e) {
    return Response::show(403,'数据库连接失败',$e->getMessage());
}

//$sql = "SELECT news_maker FROM news WHERE news_id={$id}";
$sql = "DELETE FROM news WHERE news_id={$id}";

$res = $connect->query($sql);

$data = array(
  'IsDelete'=>false
);

if($res) {
    if($connect->affected_rows == 1){
        $data['IsDelete'] = true;
        return Response::show(200,'删除成功',$data);
    } else {
        return Response::show(404,'找不到新闻数据',$data);
    }
} else {
//    echo 'sql语句执行不成功';
    return Response::show(402,'sql语句执行不成功',$data);
}


